//
//  HCCallPhonePopupView.m
//  HelloCall
//
//  Created by WangYongpeng on 13-9-26.
//  Copyright (c) 2013年 HC. All rights reserved.
//

#import "HCCallPhonePopupView.h"

@interface HCCallPhonePopupView ()

@property (nonatomic, retain)NSString* contact;
@property (nonatomic, retain)NSString* phoneNumber;

@end

@implementation HCCallPhonePopupView

@synthesize contact = m_contact;
@synthesize phoneNumber = m_phoneNumber;

- (id)initByPhoneNumber:(NSString*)phoneNumber contact:(NSString*)contact;
{
    self = [super initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
    if (nil != self)
    {
        self.contact = contact;
        self.phoneNumber = phoneNumber;
        
        UIView* view = [[UIView alloc]initWithFrame:CGRectMake(30, 150, 260, 100)];
        view.backgroundColor = [UIColor orangeColor];
        
        NSString* phoneInfoText = nil;
        if (self.contact != nil && self.contact.length > 0)
        {
            phoneInfoText = [NSString stringWithFormat:@"正在呼叫%@(%@)",self.contact,self.phoneNumber];
        }
        else
        {
            phoneInfoText = [NSString stringWithFormat:@"正在呼叫%@", self.phoneNumber];
        }
        UIFont* font = [UIFont systemFontOfSize:14];
        CGSize textSize = [phoneInfoText sizeWithFont:font];
        CGRect rect = CGRectMake((view.frame.size.width - textSize.width) / 2, (view.frame.size.height - textSize.height * 2 - 5)/2, textSize.width, textSize.height);
        UILabel* phoneInfoLabel = [[UILabel alloc] initWithFrame:rect];
        phoneInfoLabel.text = phoneInfoText;
        phoneInfoLabel.textColor = [UIColor blackColor];
        phoneInfoLabel.font = font;
        phoneInfoLabel.textAlignment = NSTextAlignmentCenter;
        phoneInfoLabel.backgroundColor = [UIColor clearColor];
        [view addSubview:phoneInfoLabel];
        [phoneInfoLabel release];
        
        NSString* waitText = @"请等待......";
        textSize = [waitText sizeWithFont:font];
        rect.origin.x = (view.frame.size.width - textSize.width) / 2;
        rect.origin.y += (5 + rect.size.height);
        rect.size = textSize;
        UILabel* waitLabel = [[UILabel alloc] initWithFrame:rect];
        waitLabel.text = waitText;
        waitLabel.textColor = [UIColor blackColor];
        waitLabel.font = font;
        waitLabel.textAlignment = NSTextAlignmentCenter;
        waitLabel.backgroundColor = [UIColor clearColor];
        [view addSubview:waitLabel];
        [waitLabel release];
        
        UIButton* closeButton = [[UIButton alloc] initWithFrame:CGRectMake(view.frame.size.width - 75, view.frame.size.height - 30, 70, 25)];
        [closeButton setTitle:@"关闭" forState:UIControlStateNormal];
        closeButton.titleLabel.font = font;
        [closeButton addTarget:self action:@selector(closeButtonPress:) forControlEvents:UIControlEventTouchUpInside];
        [closeButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [view addSubview:closeButton];
        [closeButton release];
        
        [self addSubview:view];
        [view release];
    }
    return self;
}

- (void)dealloc
{
    self.contact = nil;
    self.phoneNumber = nil;
    
    [super dealloc];
}

- (void)closeButtonPress:(UIButton*)button
{
    [self removeFromSuperview];
}


@end
